package com.bdqn.tour.servlet.Hzy;

import com.alibaba.fastjson.JSONArray;
import com.bdqn.tour.pojo.HzyOrder;
import com.bdqn.tour.service.impl.HzyOrdersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getRecentOrders")
public class GetRecentOrdersServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf-8");

        List<HzyOrder> recentOrders = new HzyOrdersServiceImpl().getRecentOrders();

        String json = JSONArray.toJSONString(recentOrders);

        resp.getWriter().write(json);
    }
}
